/**
 * @file AreaCommand.cpp
 *
 * @date 25/12/2011
 * @author Tales 
 *
 */

#include "AreaCommand.hpp"
#include "PictureState.hpp"
#include "../Graphics.hpp"

namespace yep
{

typedef void (Graphics::*AreaMethod)(const pair<int, int> &p1, const pair<int, int> &p2);
static AreaMethod methods[] =
{ &Graphics::drawRectangle, &Graphics::fillRectangle, &Graphics::drawEllipsis, &Graphics::fillEllipsis };

AreaCommand::AreaCommand(AreaCommandType type, const pair<int, int> & p1_, const pair<int, int> & p2_
		, const Color &color , int layer) :
		Command(color, layer), p1(p1_), p2(p2_)
{
	this->type = type;
}

void AreaCommand::execute(PictureState & pictureState)
{
	Graphics g(pictureState.getLayer(getLayerIndex()).getSurface());
	g.setColor(getColor());
	(g.*methods[type])(p1, p2);
}

} /* namespace yep */
